<?php

namespace App\Http\Controllers\Wechat;



use Illuminate\Http\Request;


class UserController extends HelpController
{
    /**
     * 获取用户信息
     * @return \EasyWeChat\Support\Collection
     *
     */
    public function getUser($id = null)
    {
        try{
            $userService  = $this->app->user;
            $data = $userService->get($id);
            return $this->success($data);

        }catch (\Exception $e){
            return $this->fail('获取失败'.$e->getMessage());
        }

    }

    /**
     * 获取用户列表
     * @return \EasyWeChat\Support\Collection
     *
     */
    public function getUserList($nextOpenId = null)
    {
        try{
            $userService  = $this->app->user;
            $data = $userService->lists($nextOpenId);
            return $this->success($data);

        }catch (\Exception $e){
            return $this->fail('获取失败'.$e->getMessage());
        }

    }


    /**
     * 修改用户备注
     * @param Request $request
     * @return array
     */

    public function remarkUser(Request $request)
    {
        try{
            if($request->has('remark')){
                $userService  = $this->app->user;
                $data = $userService->remark($request->get('openID'), $request->get('remark'));
                return $this->success($data);
            }else{
                return $this->fail(false,'缺少请求信息');
            }
        }catch (\Exception $e){
            return $this->fail('获取失败'.$e->getMessage());
        }
    }

}
